﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Moon.Sql
{
    internal class DataMapperDynamicImpl
    {
        public static Func<IDataReader, object> Builder(IDataReader reader, Type type, Type effectiveType)
        {
            return r => 
            {
                Dictionary<string, object> values = new Dictionary<string, object>();
                for (int i = 0; i < reader.FieldCount; i++)
                {
                    string field = reader.GetName(i);
                    object value = reader.GetValue(i);
                    values.Add(field, value is DBNull ? null : value);
                }
                return new DynamicRow(values); 
            };
        }
    }
}
